<?php

namespace app;

class Run extends Base
{

    public function run($data, $client_id)
    {
        $func = $data['type'] ?? 'demo';
        //被动ping
        if ($func === 'ping') return;
        //校验接口
        if ($this->checkType($func) === false) return;
        //校验会员
        if ($this->checkAuth($data, $client_id) === false) return;
        //校验限流
        if ($this->checkLimit() == false) return;
        //执行
        $this->$func($data);
    }

    private function demo($data)
    {
        //获取玩家对象
        $player = $this->getPlayer($data['uid']);
        //广播玩家上线信息
        $player->online();
    }

    private function send($data)
    {
        //获取玩家对象
        $player = $this->getPlayer($data['uid']);

        $player->send_msg($this->filter($data['msg']));
    }
}
